<!DOCTYPE html>
<html class="client-nojs vector-feature-night-mode-disabled vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-sticky-header-enabled" lang="en" dir="ltr"><head>
<meta charset="UTF-8">
<title>C shell</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="canonical" href="https://en.wikipedia.org/wiki/C_shell"> <link href="./mw/ext.cite.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/ext.pygments.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.icons.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.search.codex.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/user.styles.css" rel="stylesheet" type="text/css">
<meta name="ResourceLoaderDynamicStyles" content="">
<link rel="stylesheet" type="text/css" href="./mw/site.styles.css">
<link rel="stylesheet" type="text/css" href="./mw/noscript.css">
<link rel="stylesheet" type="text/css" href="./footer.css">
<link rel="stylesheet" type="text/css" href="./vector-2022.css">
</head>
<body class="skin--responsive skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject page-C_shell rootpage-C_shell skin-vector-2022 action-view">
<div class="mw-page-container">
<div class="mw-page-container-inner">
<div class="mw-content-container">
<main id="content" class="mw-body">
<header class="mw-body-header vector-page-titlebar">
<h1 id="firstHeading" class="firstHeading mw-first-heading">
<span id="openzim-page-title" class="mw-page-title-main"><span class="mw-page-title-main">C shell</span></span>
</h1>
</header>
<a id="top"></a>
<div id="bodyContent" class="vector-body ve-init-mw-desktopArticleTarget-targetContainer" aria-labelledby="firstHeading" data-mw-ve-target-container="">
<div id="mw-content-text" class="mw-body-content mw-content-ltr" lang="en" dir="ltr"><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr">
<p class="mw-empty-elt">
</p>
<style data-mw-deduplicate="TemplateStyles:r1295905060">
/* start https://en.wikipedia.org/ */
.mw-parser-output .infobox-subbox{padding:0;border:none;margin:-3px;width:auto;min-width:100%;font-size:100%;clear:none;float:none;background-color:transparent}.mw-parser-output .infobox-3cols-child{margin:auto}.mw-parser-output .infobox .navbar{font-size:100%}@media screen{html.skin-theme-clientpref-night .mw-parser-output .infobox-full-data:not(.notheme)>div:not(.notheme)[style]{background:#1f1f23!important;color:#f8f9fa}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .infobox-full-data:not(.notheme)>div:not(.notheme)[style]{background:#1f1f23!important;color:#f8f9fa}}@media(min-width:640px){body.skin--responsive .mw-parser-output .infobox-table{display:table!important}body.skin--responsive .mw-parser-output .infobox-table>caption{display:table-caption!important}body.skin--responsive .mw-parser-output .infobox-table>tbody{display:table-row-group}body.skin--responsive .mw-parser-output .infobox-table th,body.skin--responsive .mw-parser-output .infobox-table td{padding-left:inherit;padding-right:inherit}}
/* end https://en.wikipedia.org/ */
</style><table class="infobox vevent"><tbody><tr><th colspan="2" class="infobox-above summary">C shell</th></tr><tr><td colspan="2" class="infobox-image logo"><div class="infobox-caption">tcsh and sh side-by-side on a Mac OS X desktop</div></td></tr><tr><th scope="row" class="infobox-label" style="white-space: nowrap;"><a href="Programmer" title="Programmer">Original author(s)</a></th><td class="infobox-data"><a href="Bill_Joy" title="Bill Joy">Bill Joy</a></td></tr><tr><th scope="row" class="infobox-label" style="white-space: nowrap;">Initial release</th><td class="infobox-data">1978<span style="display:none"> (<span class="bday dtstart published updated">1978</span>)</span></td></tr><tr style="display: none;"><td colspan="2" class="infobox-full-data"></td></tr><tr><th scope="row" class="infobox-label" style="white-space: nowrap;"><a href="Software_release_life_cycle" title="Software release life cycle">Stable release</a></th><td class="infobox-data"><div style="margin:0px;">6.20.00
/ 24 November 2016<span style="display:none"> (<span class="bday dtstart published updated">2016-11-24</span>)</span><sup id="cite_ref-1" class="reference"><a href="#cite_note-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup></div></td></tr><tr style="display:none"><td colspan="2">
</td></tr><tr><th scope="row" class="infobox-label" style="white-space: nowrap;"><a href="Repository_(version_control)" title="Repository (version control)">Repository</a></th><td class="infobox-data"><style data-mw-deduplicate="TemplateStyles:r1126788409">
/* start https://en.wikipedia.org/ */
.mw-parser-output .plainlist ol,.mw-parser-output .plainlist ul{line-height:inherit;list-style:none;margin:0;padding:0}.mw-parser-output .plainlist ol li,.mw-parser-output .plainlist ul li{margin-bottom:0}
/* end https://en.wikipedia.org/ */
</style><div class="plainlist"><ul><li><span class="url"><a rel="nofollow" class="external text" href="http://cvsweb.netbsd.org/bsdweb.cgi/src/bin/csh/">cvsweb<wbr>.netbsd<wbr>.org<wbr>/bsdweb<wbr>.cgi<wbr>/src<wbr>/bin<wbr>/csh<wbr>/</a></span> </li></ul>
</div></td></tr><tr><th scope="row" class="infobox-label" style="white-space: nowrap;">Written in</th><td class="infobox-data"><a href="C_(programming_language)" title="C (programming language)">C</a></td></tr><tr><th scope="row" class="infobox-label" style="white-space: nowrap;"><a href="Operating_system" title="Operating system">Operating system</a></th><td class="infobox-data"><a href="Berkeley_Software_Distribution" title="Berkeley Software Distribution">BSD</a>, <a href="UNIX" class="mw-redirect" title="UNIX">UNIX</a>, <a href="UNOS_(operating_system)" title="UNOS (operating system)">UNOS</a>, <a href="Linux" title="Linux">Linux</a>, <a href="MacOS" title="MacOS">macOS</a></td></tr><tr><th scope="row" class="infobox-label" style="white-space: nowrap;"><a href="Software_categories#Categorization_approaches" title="Software categories">Type</a></th><td class="infobox-data"><a href="Unix_shell" title="Unix shell">Unix shell</a></td></tr><tr><th scope="row" class="infobox-label" style="white-space: nowrap;"><a href="Software_license" title="Software license">License</a></th><td class="infobox-data"><a href="BSD_license" class="mw-redirect" title="BSD license">BSD license</a></td></tr></tbody></table>
<p>The <b>C shell</b> (<b>csh</b> or the improved version, <b><a href="Tcsh" title="Tcsh">tcsh</a></b>) is a <a href="Unix_shell" title="Unix shell">Unix shell</a> created by <a href="Bill_Joy" title="Bill Joy">Bill Joy</a> while he was a graduate student at <a href="University_of_California%2C_Berkeley" title="University of California, Berkeley">University of California, Berkeley</a> in the late 1970s. It has been widely distributed, beginning with the 2BSD release of the <a href="Berkeley_Software_Distribution" title="Berkeley Software Distribution">Berkeley Software Distribution</a> (BSD) which Joy first distributed in 1978.<sup id="cite_ref-2" class="reference"><a href="#cite_note-2"><span class="cite-bracket">[</span>2<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-3" class="reference"><a href="#cite_note-3"><span class="cite-bracket">[</span>3<span class="cite-bracket">]</span></a></sup> Other early contributors to the ideas or the code were Michael Ubell, <a href="Eric_Allman" title="Eric Allman">Eric Allman</a>, Mike O'Brien and Jim Kulp.<sup id="cite_ref-4" class="reference"><a href="#cite_note-4"><span class="cite-bracket">[</span>4<span class="cite-bracket">]</span></a></sup>
</p><p>The C shell is a <a href="Command-line_interpreter" class="mw-redirect" title="Command-line interpreter">command processor</a> which is typically run in a text window, allowing the user to type and execute commands. The C shell can also read commands from a file, called a <a href="Shell_script" title="Shell script">script</a>. Like all Unix shells, it supports filename <a href="Wildcard_character" title="Wildcard character">wildcarding</a>, <a href="Pipeline_(Unix)" title="Pipeline (Unix)">piping</a>, <a href="Here_document" title="Here document">here documents</a>, <a href="Command_substitution" title="Command substitution">command substitution</a>, <a href="Variable_(programming)" class="mw-redirect" title="Variable (programming)">variables</a> and <a href="Control_flow" title="Control flow">control structures</a> for <a href="Conditional_(programming)" class="mw-redirect" title="Conditional (programming)">condition-testing</a> and <a href="Iteration" title="Iteration">iteration</a>. What differentiated the C shell from others, especially in the 1980s, were its interactive features and overall style. Its new features made it easier and faster to use. The overall style of the language looked more like <a href="C_(programming_language)" title="C (programming language)">C</a> and was seen as more readable.
</p><p>On many systems, such as <a href="MacOS" title="MacOS">macOS</a> and <a href="Red_Hat_Linux" title="Red Hat Linux">Red Hat Linux</a>, csh is actually <a href="Tcsh" title="Tcsh">tcsh</a>, an improved version of csh. Often one of the two files is either a <a href="Hard_link" title="Hard link">hard link</a> or a <a href="Symbolic_link" title="Symbolic link">symbolic link</a> to the other, so that either name refers to the same improved version of the C shell. The original csh source code and binary are part of <a href="NetBSD" title="NetBSD">NetBSD</a>.
</p><p>On <a href="Debian" title="Debian">Debian</a> and some derivatives (including <a href="Ubuntu_(operating_system)" class="mw-redirect" title="Ubuntu (operating system)">Ubuntu</a>), there are two different packages: csh and tcsh. The former is based on the original BSD version of csh<sup id="cite_ref-5" class="reference"><a href="#cite_note-5"><span class="cite-bracket">[</span>5<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-6" class="reference"><a href="#cite_note-6"><span class="cite-bracket">[</span>6<span class="cite-bracket">]</span></a></sup> and the latter is the improved tcsh.<sup id="cite_ref-7" class="reference"><a href="#cite_note-7"><span class="cite-bracket">[</span>7<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-8" class="reference"><a href="#cite_note-8"><span class="cite-bracket">[</span>8<span class="cite-bracket">]</span></a></sup>
</p><p>tcsh added filename and command completion and command line editing concepts borrowed from the <a href="TOPS-20#TENEX" title="TOPS-20">Tenex</a> system, which is the source of the "t".<sup id="cite_ref-Greer_9-0" class="reference"><a href="#cite_note-Greer-9"><span class="cite-bracket">[</span>9<span class="cite-bracket">]</span></a></sup> Because it only added functionality and did not change what already existed, tcsh remained <a href="Backward_compatible" class="mw-redirect" title="Backward compatible">backward compatible</a><sup id="cite_ref-10" class="reference"><a href="#cite_note-10"><span class="cite-bracket">[</span>10<span class="cite-bracket">]</span></a></sup> with the original C shell. Though it started as a side branch from the original source tree Joy had created, tcsh is now the main branch for ongoing development. tcsh is very stable but new releases continue to appear roughly once a year, consisting mostly of minor bug fixes.<sup id="cite_ref-11" class="reference"><a href="#cite_note-11"><span class="cite-bracket">[</span>11<span class="cite-bracket">]</span></a></sup>
</p>
<meta property="mw:PageProp/toc">
<div class="mw-heading mw-heading2"><h2 id="Design_objectives_and_features">Design objectives and features</h2></div>
<p>The main design objectives for the C shell were that it should look more like the <a href="C_(programming_language)" title="C (programming language)">C programming language</a> and that it should be better for interactive use.
</p>
<div class="mw-heading mw-heading3"><h3 id="More_like_C">More like C</h3></div>
<p>The Unix system had been written almost exclusively in C, so the C shell's first objective was a command language that was more stylistically consistent with the rest of the system. The keywords, the use of parentheses, and the C shell's built-in expression grammar and support for arrays were all strongly influenced by C.
</p><p>By today's standards, C shell may not seem particularly more C-like than many other popular scripting languages. But through the 1980s and '90s, the difference was seen as striking, particularly when compared to <a href="Bourne_shell" title="Bourne shell">Bourne shell</a> (also known as <i>sh</i>), the then-dominant shell written by <a href="Stephen_R._Bourne" title="Stephen R. Bourne">Stephen Bourne</a> at <a href="Bell_Labs" title="Bell Labs">Bell Labs</a>. This example illustrates the C shell's more conventional <a href="Operator_(computer_programming)" title="Operator (computer programming)">expression operators</a> and <a href="Syntax_(programming_languages)" title="Syntax (programming languages)">syntax</a>.
</p>
<style data-mw-deduplicate="TemplateStyles:r1088965794">
/* start https://en.wikipedia.org/ */
@media(min-width:720px){.mw-parser-output .columns-start .column{float:left;min-width:20em}.mw-parser-output .columns-2 .column{width:50%}.mw-parser-output .columns-3 .column{width:33.3%}.mw-parser-output .columns-4 .column{width:25%}.mw-parser-output .columns-5 .column{width:20%}}
/* end https://en.wikipedia.org/ */
</style><div class="columns-start columns-2" style="width: 60em"><div class="column">
<p>Bourne shell
</p>
<div class="mw-highlight mw-highlight-lang-bash mw-content-ltr" dir="ltr"><pre><span class="ch">#!/bin/sh</span>
<span class="k">if</span><span class="w"> </span><span class="o">[</span><span class="w"> </span><span class="nv">$days</span><span class="w"> </span>-gt<span class="w"> </span><span class="m">365</span><span class="w"> </span><span class="o">]</span>
<span class="k">then</span>
<span class="w"> </span><span class="nb">echo</span><span class="w"> </span>This<span class="w"> </span>is<span class="w"> </span>over<span class="w"> </span>a<span class="w"> </span>year.
<span class="k">fi</span>
</pre></div>
</div><div class="column">
<p>C shell
</p>
<div class="mw-highlight mw-highlight-lang-csh mw-content-ltr" dir="ltr"><pre><span class="c">#!/bin/csh</span>
<span class="k">if</span> <span class="o">(</span> <span class="nv">$days</span> > 365 <span class="o">)</span> <span class="k">then</span>
<span class="k"> </span><span class="nb">echo </span>This is over a year.
<span class="k">endif</span>
</pre></div></div><div style="clear: both"></div></div>
<p>The Bourne sh lacked an <a href="Expression_(programming)" class="mw-redirect" title="Expression (programming)">expression grammar</a>. The square bracketed condition had to be evaluated by the slower means of running the external <a href="Test_(Unix)" title="Test (Unix)">test</a> program. sh's <code>if</code> command took its argument words as a new command to be run as a <a href="Process_(computing)" title="Process (computing)">child process</a>. If the child exited with a zero <a href="Return_code" class="mw-redirect" title="Return code">return code</a>, sh would look for a <code>then</code> clause (a separate statement, but often written joined on the same line with a semicolon) and run that nested block. Otherwise, it would run the else. <a href="Hard_link" title="Hard link">Hard-linking</a> the test program as both "<code>test</code>" and "<code>[</code>" gave the notational advantage of the square brackets and the appearance that the functionality of test was part of the sh language. sh's use of a reversed keyword to mark the end of a control block was a style borrowed from <a href="ALGOL_68" title="ALGOL 68">ALGOL 68</a>.<sup id="cite_ref-12" class="reference"><a href="#cite_note-12"><span class="cite-bracket">[</span>12<span class="cite-bracket">]</span></a></sup>
</p><p>By contrast, csh could evaluate the expression directly, which made it faster. It also claimed better readability: Its expressions used a <a href="Formal_grammar" title="Formal grammar">grammar</a> and a set of operators mostly copied from C, none of its keywords were reversed and the overall style was also more like C.
</p><p>Here is a second example, comparing scripts that calculate the first 10 powers of 2.
</p>
<div class="columns-start columns-2" style="width: 60em"><div class="column">
<p>Bourne shell
</p>
<div class="mw-highlight mw-highlight-lang-bash mw-content-ltr" dir="ltr"><pre><span class="ch">#!/bin/sh</span>
<span class="nv">i</span><span class="o">=</span><span class="m">2</span>
<span class="nv">j</span><span class="o">=</span><span class="m">1</span>
<span class="k">while</span><span class="w"> </span><span class="o">[</span><span class="w"> </span><span class="nv">$j</span><span class="w"> </span>-le<span class="w"> </span><span class="m">10</span><span class="w"> </span><span class="o">]</span>
<span class="k">do</span>
<span class="w"> </span><span class="nb">echo</span><span class="w"> </span><span class="s1">'2 **'</span><span class="w"> </span><span class="nv">$j</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nv">$i</span>
<span class="w"> </span><span class="nv">i</span><span class="o">=</span><span class="sb">`</span>expr<span class="w"> </span><span class="nv">$i</span><span class="w"> </span><span class="s1">'*'</span><span class="w"> </span><span class="m">2</span><span class="sb">`</span>
<span class="w"> </span><span class="nv">j</span><span class="o">=</span><span class="sb">`</span>expr<span class="w"> </span><span class="nv">$j</span><span class="w"> </span>+<span class="w"> </span><span class="m">1</span><span class="sb">`</span>
<span class="k">done</span>
</pre></div>
</div><div class="column">
<p>C shell
</p>
<div class="mw-highlight mw-highlight-lang-csh mw-content-ltr" dir="ltr"><pre><span class="c">#!/bin/csh</span>
<span class="nb">set </span><span class="nv">i</span> <span class="o">=</span> 2
<span class="nb">set </span><span class="nv">j</span> <span class="o">=</span> 1
<span class="k">while</span> <span class="o">(</span> <span class="nv">$j</span> <<span class="o">=</span> 10 <span class="o">)</span>
<span class="nb">echo</span> <span class="s1">'2 **'</span> <span class="nv">$j</span> <span class="o">=</span> <span class="nv">$i</span>
@ i *<span class="o">=</span> 2
@ j++
<span class="k">end</span>
</pre></div></div><div style="clear: both"></div></div>
<p>Again because of the lack of an expression grammar, the sh script uses <a href="Command_substitution" title="Command substitution">command substitution</a> and the <a href="Expr" title="Expr">expr</a> command. (Modern <a href="POSIX_shell" class="mw-redirect" title="POSIX shell">POSIX shell</a> <i>does</i> have such a grammar: the statement could be written <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">i=$((i * 2))</code> or <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">: "$((i *= 2))"</code>.)
</p><p>Finally, here is a third example, showing the differing styles for a <a href="Switch_statement" title="Switch statement">switch statement</a>.
</p>
<div class="columns-start columns-2" style="width: 60em"><div class="column">
<p>Bourne shell
</p>
<div class="mw-highlight mw-highlight-lang-bash mw-content-ltr" dir="ltr"><pre><span class="ch">#!/bin/sh</span>
<span class="k">for</span><span class="w"> </span>i<span class="w"> </span><span class="k">in</span><span class="w"> </span>d*
<span class="k">do</span>
<span class="w"> </span><span class="k">case</span><span class="w"> </span><span class="nv">$i</span><span class="w"> </span><span class="k">in</span>
<span class="w"> </span>d?<span class="o">)</span><span class="w"> </span><span class="nb">echo</span><span class="w"> </span><span class="nv">$i</span><span class="w"> </span>is<span class="w"> </span>short<span class="w"> </span><span class="p">;;</span>
<span class="w"> </span>*<span class="o">)</span><span class="w"> </span><span class="nb">echo</span><span class="w"> </span><span class="nv">$i</span><span class="w"> </span>is<span class="w"> </span>long<span class="w"> </span><span class="p">;;</span>
<span class="w"> </span><span class="k">esac</span>
<span class="k">done</span>
</pre></div>
</div><div class="column">
<p>C shell
</p>
<div class="mw-highlight mw-highlight-lang-csh mw-content-ltr" dir="ltr"><pre><span class="c">#!/bin/csh</span>
<span class="k">foreach </span>i <span class="o">(</span> d* <span class="o">)</span>
<span class="k">switch</span> <span class="o">(</span> <span class="nv">$i</span> <span class="o">)</span>
<span class="k">case </span>d?:
<span class="nb">echo</span> <span class="nv">$i</span> is short
<span class="k">breaksw</span>
<span class="k"> default</span>:
<span class="nb">echo</span> <span class="nv">$i</span> is long
<span class="k">endsw</span>
<span class="k">end</span>
</pre></div></div><div style="clear: both"></div></div>
<p>In the sh script, "<code>;;</code>" marks the end of each case because sh disallows null statements otherwise.
</p>
<div class="mw-heading mw-heading3"><h3 id="Improvements_for_interactive_use">Improvements for interactive use</h3></div>
<p>The second objective was that the C shell should be better for interactive use. It introduced numerous new features that made it easier, faster and more <a href="User-friendly" class="mw-redirect" title="User-friendly">friendly</a> to use by typing commands at a terminal. Users could get things done with a lot fewer keystrokes and it ran faster. The most significant of these new features were the history and editing mechanisms, aliases, directory stacks, tilde notation, cdpath, job control, and path hashing. These new features proved very popular, and many of them have since been copied by other Unix shells.
</p>
<div class="mw-heading mw-heading4"><h4 id="History">History</h4></div>
<p>History allows users to recall previous commands and rerun them by typing only a few quick keystrokes. For example, typing two exclamation marks ("<code>!!</code>")<sup id="cite_ref-13" class="reference"><a href="#cite_note-13"><span class="cite-bracket">[</span>13<span class="cite-bracket">]</span></a></sup> as a command causes the immediately preceding command to be run. Other short keystroke combinations, e.g., "<code>!$</code>" (meaning "the final argument of the previous command"), allow bits and pieces of previous commands to be pasted together and edited to form a new command.
</p>
<div class="mw-heading mw-heading4"><h4 id="Editing_operators">Editing operators</h4></div>
<p>Editing can be done not only on the text of a previous command, but also on variable substitutions. Operators range from simple string search/replace to parsing a pathname to extract a specific segment.
</p>
<div class="mw-heading mw-heading4"><h4 id="Aliases">Aliases</h4></div>
<p>Aliases allow the user to type the name of an alias and have the C shell expand it internally into whatever set of words the user has defined. For many simple situations, aliases run faster and are more convenient than scripts.
</p>
<div class="mw-heading mw-heading4"><h4 id="Directory_stack">Directory stack</h4></div>
<p>The directory <a href="Stack_(data_structure)" class="mw-redirect" title="Stack (data structure)">stack</a> allows the user to <a href="Pushd_and_popd" title="Pushd and popd">push or pop</a> the <a href="Current_working_directory" class="mw-redirect" title="Current working directory">current working directory</a>, making it easier to jump back and forth between different places in the filesystem.
</p>
<div class="mw-heading mw-heading4"><h4 id="Tilde_notation">Tilde notation</h4></div>
<p>Tilde notation offers a shorthand way of specifying pathnames relative to the <a href="Home_directory" title="Home directory">home directory</a> using the "<code>~</code>" character.
</p>
<div class="mw-heading mw-heading4"><h4 id="Filename_completion">Filename completion</h4></div>
<p>The <a href="Esc_key" title="Esc key">escape key</a> can be used interactively to show possible completions of a filename at the end of the current command line.
</p>
<div class="mw-heading mw-heading4"><h4 id="Cdpath">Cdpath</h4></div>
<p>Cdpath extends the notion of a <a href="PATH_(variable)" title="PATH (variable)">search path</a> to the <code>cd</code> (change directory) command: If the specified directory is not in the <a href="Current_directory" class="mw-redirect" title="Current directory">current directory</a>, csh will try to find it in the cdpath directories.
</p>
<div class="mw-heading mw-heading4"><h4 id="Job_control">Job control</h4></div>
<p>Well into the 1980s, most users only had simple character-mode terminals that precluded multiple windows, so they could only work on one task at a time. The C shell's job control allowed the user to suspend the current activity and create a new instance of the C shell, called a job, by typing <code><a href="Control-Z" class="mw-redirect" title="Control-Z">^Z</a></code>. The user could then switch back and forth between jobs using the <kbd>fg</kbd> command. The active job was said to be in the foreground. Other jobs were said to be either suspended (stopped) or running in the <a href="Background_process" title="Background process">background</a>.
</p>
<div class="mw-heading mw-heading4"><h4 id="Path_hashing">Path hashing</h4></div>
<p>Path hashing speeds up the C shell's search for executable files. Rather than performing a filesystem call in each path directory, one at a time, until it either finds the file or runs out of possibilities, the C shell consults an internal <a href="Hash_table" title="Hash table">hash table</a> built by scanning the path directories. That table can usually tell the C shell where to find the file (if it exists) without having to search and can be refreshed with the <code>rehash</code> command.
</p>
<div class="mw-heading mw-heading2"><h2 id="Overview_of_the_language">Overview of the language</h2></div>
<p>The C shell operates one line at a time. Each line is <a href="Lexical_analysis" title="Lexical analysis">tokenized</a> into a set of words separated by spaces or other characters with special meaning, including parentheses, piping and input/output redirection operators, semicolons, and ampersands.
</p>
<div class="mw-heading mw-heading3"><h3 id="Basic_statements">Basic statements</h3></div>
<p>A basic statement is one that simply runs a command. The first word is taken as name of the command to be run and may be either an internal command, e.g., <code>echo</code>, or an external command. The rest of the words are passed as arguments to the command.
</p><p>At the basic statement level, here are some of the features of the grammar:
</p>
<div class="mw-heading mw-heading4"><h4 id="Wildcarding">Wildcarding</h4></div>
<p>The C shell, like all Unix shells, treats any command-line argument that contains wildcard characters as a pattern and replaces it with the list of all the filenames that match (see <a href="Globbing" class="mw-redirect" title="Globbing">globbing</a>).
</p>
<ul><li><code>*</code> matches any number of characters.</li>
<li><code>?</code> matches any single character.</li>
<li><code>[</code>...<code>]</code> matches any of the characters inside the square brackets. Ranges are allowed, using the hyphen.</li>
<li><code>[^</code>...<code>]</code> matches any character <i>not</i> in the set.</li></ul>
<p>The C shell also introduced several notational conveniences (sometimes known as <a href="Extended_globbing" class="mw-redirect" title="Extended globbing">extended globbing</a>), since copied by other Unix shells.
</p>
<ul><li><code>abc{def,ghi}</code> is <a href="Alternation_(string_expansion)" class="mw-redirect" title="Alternation (string expansion)">alternation</a> (aka <a href="Bash_(Unix_shell)#Brace_expansion" title="Bash (Unix shell)">brace expansion</a>) and expands to <i>abcdef</i> <i>abcghi</i>.</li>
<li><code>~</code> means the current user's home directory.</li>
<li><code>~user</code> means <i>user'</i>s home directory.</li></ul>
<p>Multiple directory-level wildcards, e.g., "<code>*/*.c</code>", are supported.
</p><p>Since version 6.17.01, recursive wildcarding à la <a href="Z_shell" title="Z shell">zsh</a> (e.g. "<code>**/*.c</code>" or "<code>***/*.html</code>") is also supported with the <code>globstar</code> option.
</p><p>Giving the shell the responsibility for interpreting wildcards was an important decision on Unix. It meant that wildcards would work with every command, and always in the same way. However, the decision relied on Unix's ability to pass long argument lists efficiently through the <a href="Exec_(system_call)" title="Exec (system call)">exec</a> system call that csh uses to execute commands. By contrast, on <a href="Windows" class="mw-redirect" title="Windows">Windows</a>, wildcard interpretation is conventionally performed by each application. This is a legacy of MS-DOS, which only allowed a 128-byte command line to be passed to an application, making wildcarding by the DOS command prompt impractical. Although modern <a href="Microsoft_Windows" title="Microsoft Windows">Windows</a> can pass command lines of up to roughly 32K <a href="Unicode" title="Unicode">Unicode</a> characters, the burden for wildcard interpretation remains with the application.
</p>
<div class="mw-heading mw-heading4"><h4 id="I/O_redirection">I/O redirection</h4></div>
<p>By default, when csh runs a command, the command inherits the csh's stdio file handles for <a href="Stdin" class="mw-redirect" title="Stdin">stdin</a>, <a href="Stdout" class="mw-redirect" title="Stdout">stdout</a> and <a href="Stderr" class="mw-redirect" title="Stderr">stderr</a>, which normally all point to the <a href="Console_window" class="mw-redirect" title="Console window">console window</a> where the C shell is running. The i/o redirection operators allow the command to use a file instead for input or output.
</p>
<ul><li><code>> <em>file</em></code> means stdout will be written to <i>file</i>, overwriting it if it exists, and creating it if it doesn't. Errors still come to the shell window.</li>
<li><code>>& <em>file</em></code> means both stdout and stderr will be written to <i>file</i>, overwriting it if it exists, and creating it if it doesn't.</li>
<li><code>>> <em>file</em></code> means stdout will be appended at the end of <i>file</i>.</li>
<li><code>>>& <em>file</em></code> means both stdout and stderr will be appended at the end of <i>file</i>.</li>
<li><code>< <em>file</em></code> means stdin will be read from <i>file</i>.</li>
<li><code><< <em>string</em></code> is a <a href="Here_document" title="Here document">here document</a>. Stdin will read the following lines up to the one that matches <i>string</i>.</li></ul>
<p>Redirecting stderr alone isn't possible without the aid of a sub-shell.
</p>
<div class="mw-highlight mw-highlight-lang-csh mw-content-ltr" dir="ltr"><pre><span class="nb">set </span><span class="nv">filter</span> <span class="o">=</span> <span class="s2">"$home"</span><span class="s1">'/filter'</span>
mkfifo <span class="s2">"$filter"</span>
cat <span class="s2">"$filter"</span> & <span class="o">(</span> <span class="o">(</span> ls /root/ || <span class="nb">echo </span>No access. <span class="o">)</span> > <span class="s2">"$filter"</span> <span class="o">)</span> >& /dev/null
</pre></div>
<p>Systems supporting file descriptors as files may use the following workaround.
</p>
<div class="mw-highlight mw-highlight-lang-csh mw-content-ltr" dir="ltr"><pre><span class="o">(</span> <span class="o">(</span> <span class="o">(</span> <span class="nb">echo </span>ok <span class="p">;</span> <span class="s1">''</span> <span class="o">)</span> > /dev/fd/0 <span class="o">)</span> >& /dev/null < /dev/fd/1 <span class="o">)</span> | <span class="o">(</span> <span class="nb">echo</span> <span class="s2">"$<"</span> <span class="nb">bye</span> <span class="o">)</span>
</pre></div>
<div class="mw-heading mw-heading4"><h4 id="Joining">Joining</h4></div>
<p>Commands can be joined on the same line.
</p>
<ul><li><code>;</code> means run the first command and then the next.</li>
<li><code>&&</code> means run the first command and, if it succeeds with a 0 <a href="Return_code" class="mw-redirect" title="Return code">return code</a>, run the next.</li>
<li><code>||</code> means run the first command and, if it fails with a non-zero return code, run the next.</li></ul>
<div class="mw-heading mw-heading4"><h4 id="Piping">Piping</h4></div>
<p>Commands can be connected using a pipe, which causes the output of one command to be fed into the input of the next. Both commands run <a href="Concurrency_(computer_science)" title="Concurrency (computer science)">concurrently</a>.
</p>
<ul><li><code>|</code> means connect stdout to stdin of the next command. Errors still come to the shell window.</li>
<li><code>|&</code> means connect both stdout and stderr to stdin of the next command.</li></ul>
<p>Running concurrently means "in parallel". In a <a href="Multi-core_processor" title="Multi-core processor">multi-core</a> (multiple processor) system, the piped commands may literally be executing at the same time, otherwise the <a href="Scheduling_(computing)" title="Scheduling (computing)">scheduler</a> in the operating system <a href="Time_slice" class="mw-redirect" title="Time slice">time-slices</a> between them.
</p><p>Given a command, e.g., "<code>a | b</code>", the shell creates a <a href="Pipeline_(computing)" title="Pipeline (computing)">pipe</a>, then starts both <code>a</code> and <code>b</code> with stdio for the two commands redirected so that <code>a</code> writes its stdout into the input of the pipe while <code>b</code> reads stdin from the output of the pipe. Pipes are implemented by the operating system with a certain amount of buffering so that <code>a</code> can write for a while before the pipe fills but once the pipe fills any new write will block inside the OS until <code>b</code> reads enough to unblock new writes. If <code>b</code> tries to read more data than is available, it will block until <code>a</code> has written more data or until the pipe closes, e.g., if <code>a</code> exits.
</p>
<div class="mw-heading mw-heading4"><h4 id="Variable_substitution">Variable substitution</h4></div>
<p>If a word contains a dollar sign, "<code>$</code>", the following characters are taken as the name of a variable and the reference is replaced by the value of that variable. Various editing operators, typed as suffixes to the reference, allow pathname editing (e.g., "<code>:e</code>" to extract just the extension) and other operations.
</p>
<div class="mw-heading mw-heading4"><h4 id="Quoting_and_escaping">Quoting and escaping</h4></div>
<p>Quoting mechanisms allow otherwise special characters, such as whitespace, wildcards, parentheses, and dollar signs, to be taken as <a href="Literal_(computer_science)" class="mw-redirect" title="Literal (computer science)">literal</a> text.
</p>
<ul><li><code>\</code> means take the next character as an ordinary literal character.</li>
<li><code>"</code><i>string</i><code>"</code> is a weak quote. Enclosed whitespace and wildcards are taken as literals, but variable and command substitutions are still performed.</li>
<li><code>'</code><i>string</i><code>'</code> is a strong quote. The entire enclosed string is taken as a literal.</li></ul>
<p>Double quotes inside double quotes should be escaped with <code>"\""</code>. The same applies to the dollar symbol, to prevent variable expansion <code>"\$"</code>. For backticks, to prevent command substitution nesting, single quotes are required <code>"'\`'"</code>.
</p>
<div class="mw-heading mw-heading4"><h4 id="Command_substitution">Command substitution</h4></div>
<p>Command substitution allows the output of one command to be used as arguments to another.
</p>
<ul><li><code>`</code><i>command</i><code>`</code> means take the output of <i>command</i>, parse it into words and paste them back into the command line.</li></ul>
<p>The following is an example of nested command substitutions with <a href="Leaning_toothpick_syndrome" title="Leaning toothpick syndrome">Leaning toothpick syndrome</a>:
</p>
<div class="mw-highlight mw-highlight-lang-csh mw-content-ltr" dir="ltr"><pre><span class="nb">echo</span> <span class="s2">"`echo "</span><span class="se">\"\`</span><span class="s2">"echo "</span><span class="se">\"\\\"\\\`\"</span><span class="s2">"echo "</span><span class="se">\"\\\"\\\\\\\"\\\\\\\`\\\"\"</span><span class="s2">"echo "</span><span class="se">\"\\\"\\\\\\\"\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\`\\\\\\\"\\\"\"</span><span class="s2">"echo "</span><span class="se">\"\\\"\\\\\\\"\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\`\\\\\\\\\\\\\\\"\\\\\\\"\\\"\"</span><span class="s2">"pwd"</span><span class="se">\"\\\"\\\\\\\"\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\`\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\`\\\\\\\\\\\\\\\"\\\\\\\"\\\\\\\`\\\\\\\"\\\"\\\`\\\"\"\`\"</span><span class="s2">"`"</span>
</pre></div>
<div class="mw-heading mw-heading4"><h4 id="Background_execution">Background execution</h4></div>
<p>Normally, when the C shell starts a command, it waits for the command to finish before giving the user another prompt signaling that a new command can be typed.
</p>
<ul><li><i>command</i><code> &</code> means start <i>command</i> in the background and prompt immediately for a new command.</li></ul>
<div class="mw-heading mw-heading4"><h4 id="Subshells">Subshells</h4></div>
<p>A subshell is a separate child copy of the shell that inherits the current state but can then make changes, e.g., to the current directory, without affecting the parent.
</p>
<ul><li><code>( </code><i>commands</i><code> )</code> means run <i>commands</i> in a subshell.</li></ul>
<div class="mw-heading mw-heading3"><h3 id="Control_structures">Control structures</h3></div>
<p>The C shell provides control structures for both <a href="Conditional_(programming)" class="mw-redirect" title="Conditional (programming)">condition-testing</a> and <a href="Iteration" title="Iteration">iteration</a>. The condition-testing control structures are the if and switch statements. The iteration control structures are the while, foreach and repeat statements.
</p>
<div class="mw-heading mw-heading4"><h4 id="if_statement">if statement</h4></div>
<p>There are two forms of the <a href="If_statement" class="mw-redirect" title="If statement">if statement</a>. The short form is typed on a single line but can specify only a single command if the expression is true.
</p>
<div class="mw-highlight mw-highlight-lang-csh mw-content-ltr" dir="ltr"><pre><span class="k">if</span> <span class="o">(</span> expression <span class="o">)</span> command
</pre></div>
<p>The long form uses then, else and endif keywords to allow for blocks of commands to be nested inside the condition.
</p>
<div class="mw-highlight mw-highlight-lang-csh mw-content-ltr" dir="ltr"><pre><span class="k">if</span> <span class="o">(</span> expression1 <span class="o">)</span> <span class="k">then</span>
<span class="k"> </span>commands
<span class="k">else if</span> <span class="o">(</span> expression2 <span class="o">)</span> <span class="k">then</span>
<span class="k"> </span>commands
...
<span class="k">else</span>
<span class="k"> </span>commands
<span class="k">endif</span>
</pre></div>
<p>If the else and if keywords appear on the same line, csh chains, rather than nests them; the block is terminated with a single endif.
</p>
<div class="mw-heading mw-heading4"><h4 id="switch_statement">switch statement</h4></div>
<p>The switch statement compares a string against a list of patterns, which may contain wildcard characters. If nothing matches, the default action, if there is one, is taken.
</p>
<div class="mw-highlight mw-highlight-lang-csh mw-content-ltr" dir="ltr"><pre><span class="k">switch</span> <span class="o">(</span> string <span class="o">)</span>
<span class="k">case </span>pattern1:
commands
<span class="k">breaksw</span>
<span class="k"> case </span>pattern2:
commands
<span class="k">breaksw</span>
...
<span class="k">default</span>:
commands
<span class="k">breaksw</span>
<span class="k">endsw</span>
</pre></div>
<div class="mw-heading mw-heading4"><h4 id="while_statement">while statement</h4></div>
<p>The <a href="While_loop" title="While loop">while statement</a> evaluates an expression. If it is true, the shell runs the nested commands and then repeats for as long as the expression remains true.
</p>
<div class="mw-highlight mw-highlight-lang-csh mw-content-ltr" dir="ltr"><pre><span class="k">while</span> <span class="o">(</span> expression <span class="o">)</span>
commands
<span class="k">end</span>
</pre></div>
<div class="mw-heading mw-heading4"><h4 id="foreach_statement">foreach statement</h4></div>
<p>The foreach statement takes a list of values, usually a list of filenames produced by wildcarding, and then for each, sets the loop variable to that value and runs the nested commands.
</p>
<div class="mw-highlight mw-highlight-lang-csh mw-content-ltr" dir="ltr"><pre><span class="k">foreach </span>loop-variable <span class="o">(</span> list-of-values <span class="o">)</span>
commands
<span class="k">end</span>
</pre></div>
<div class="mw-heading mw-heading4"><h4 id="repeat_statement">repeat statement</h4></div>
<p>The repeat statement repeats a single command an integral number of times.
</p>
<div class="mw-highlight mw-highlight-lang-csh mw-content-ltr" dir="ltr"><pre><span class="nb">repeat </span>integer command
</pre></div>
<div class="mw-heading mw-heading3"><h3 id="Variables">Variables</h3></div>
<p>The C shell implements both shell and <a href="Environment_variable" title="Environment variable">environment variables</a>.<sup id="cite_ref-USDT_14-0" class="reference"><a href="#cite_note-USDT-14"><span class="cite-bracket">[</span>14<span class="cite-bracket">]</span></a></sup> Environment variables, created using the <code>setenv</code> statement, are always simple strings, passed to any <a href="Process_(computing)" title="Process (computing)">child processes</a>, which retrieve these variables via the <a href="Exec_(system_call)#envp" title="Exec (system call)"><code>envp[]</code></a> argument to <a href="Main_function_(programming)" class="mw-redirect" title="Main function (programming)"><code>main()</code></a>.
</p><p>Shell variables, created using the <code>set</code> or <code>@</code> statements, are internal to C shell. They are not passed to child processes. Shell variables can be either simple strings or arrays of strings. Some of the shell variables are predefined and used to control various internal C shell options, e.g., what should happen if a wildcard fails to match anything.
</p><p>In current versions of csh, strings can be of arbitrary length, well into millions of characters.
</p><p>Variables can be enlarged as needed. However, if it's desirable to work on a fixed size, the following syntax is preferred.
</p>
<div class="mw-highlight mw-highlight-lang-csh mw-content-ltr" dir="ltr"><pre><span class="c"># Creates a variable large enough to hold 1024 elements.</span>
<span class="nb">set </span><span class="nv">fixed</span> <span class="o">=</span> <span class="o">{</span>,<span class="o">}{</span>,<span class="o">}{</span>,<span class="o">}{</span>,<span class="o">}{</span>,<span class="o">}{</span>,<span class="o">}{</span>,<span class="o">}{</span>,<span class="o">}{</span>,<span class="o">}{</span>,<span class="o">}</span>
</pre></div>
<div class="mw-heading mw-heading3"><h3 id="Expressions">Expressions</h3></div>
<p>The C shell implements a 32-bit integer expression grammar with operators borrowed from C but with a few additional operators for string comparisons and filesystem tests, e.g., testing for the existence of a file. Operators must be separated by whitespace from their operands. Variables are referenced as <code>$</code><i>name</i>.
</p><p><a href="Operator_precedence" class="mw-redirect" title="Operator precedence">Operator precedence</a> is also borrowed from C, but with different <a href="Operator_associativity" title="Operator associativity">operator associativity</a> rules to resolve the ambiguity of what comes first in a sequence of equal precedence operators. In C, the associativity is left-to-right for most operators; in C shell, it is right-to-left. For example,
</p>
<div class="columns-start columns-2" style="width: 60em"><div class="column">
<div class="mw-highlight mw-highlight-lang-c mw-content-ltr" dir="ltr"><pre><span class="c1">// C groups from the left</span>
<span class="kt">int</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">10</span><span class="w"> </span><span class="o">/</span><span class="w"> </span><span class="mi">5</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="mi">2</span><span class="p">;</span>
<span class="n">printf</span><span class="p">(</span><span class="w"> </span><span class="s">"%d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="p">);</span><span class="w"> </span><span class="c1">// prints 4</span>
<span class="n">i</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">7</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mi">4</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">2</span><span class="p">;</span>
<span class="n">printf</span><span class="p">(</span><span class="w"> </span><span class="s">"%d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="p">);</span><span class="w"> </span><span class="c1">// prints 5</span>
<span class="n">i</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="w"> </span><span class="o">>></span><span class="w"> </span><span class="mi">1</span><span class="w"> </span><span class="o"><<</span><span class="w"> </span><span class="mi">4</span><span class="p">;</span>
<span class="n">printf</span><span class="p">(</span><span class="w"> </span><span class="s">"%d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="p">);</span><span class="w"> </span><span class="c1">// prints 16</span>
</pre></div>
</div><div class="column">
<div class="mw-highlight mw-highlight-lang-csh mw-content-ltr" dir="ltr"><pre><span class="c"># C shell groups from the right</span>
@ <span class="nv">i</span> <span class="o">=</span> 10 / 5 * 2
<span class="nb">echo</span> <span class="nv">$i</span> <span class="c"># prints 1</span>
@ <span class="nv">i</span> <span class="o">=</span> 7 - 4 + 2
<span class="nb">echo</span> <span class="nv">$i</span> <span class="c"># prints 1</span>
@ <span class="nv">i</span> <span class="o">=</span> <span class="o">(</span> 2 >> 1 << 4 <span class="o">)</span>
<span class="nb">echo</span> <span class="nv">$i</span> <span class="c"># prints 0</span>
</pre></div></div><div style="clear: both"></div></div>
<p>The parentheses in the C shell example are to avoid having the bit-shifting operators confused as I/O redirection operators. In either language, parentheses can always be used to explicitly specify the desired order of evaluation, even if only for clarity.
</p><p>Return values are limited to 8-bit. For <code>exit</code> expressions, the unary negation operator can be used for 32-bit evaluation.
</p>
<div class="mw-highlight mw-highlight-lang-csh mw-content-ltr" dir="ltr"><pre><span class="nb">exit</span> ! ! 256 <span class="c"># Returns 1.</span>
</pre></div>
<div class="mw-heading mw-heading2"><h2 id="Reception">Reception</h2></div>
<p>Although <a href="Stephen_R._Bourne" title="Stephen R. Bourne">Stephen Bourne</a> himself acknowledged that csh was superior to his shell for interactive use,<sup id="cite_ref-bourne198310_15-0" class="reference"><a href="#cite_note-bourne198310-15"><span class="cite-bracket">[</span>15<span class="cite-bracket">]</span></a></sup> it has never been as popular for scripting.
</p><p>In 1983, both csh and Bourne shell were available for Charles River Data Systems' <a href="UNOS_(operating_system)" title="UNOS (operating system)">UNOS</a> operating system among other UNIX tools under <a href="Bell_Laboratories" class="mw-redirect" title="Bell Laboratories">Bell Laboratories</a> license.<sup id="cite_ref-16" class="reference"><a href="#cite_note-16"><span class="cite-bracket">[</span>16<span class="cite-bracket">]</span></a></sup>
</p><p>Initially, and through the 1980s, csh could not be guaranteed to be present on all Unix and Unix-like systems, but sh could, which made it a better choice for any scripts that might have to run on other machines. By the mid-1990s, csh was widely available, but the use of csh for scripting faced new criticism by the <a href="POSIX" title="POSIX">POSIX</a> committee,<sup id="cite_ref-17" class="reference"><a href="#cite_note-17"><span class="cite-bracket">[</span>17<span class="cite-bracket">]</span></a></sup> which specified that there should only be one preferred shell, the <a href="KornShell" title="KornShell">KornShell</a>, for both interactive and scripting purposes. The C shell also faced criticism from others<sup id="cite_ref-18" class="reference"><a href="#cite_note-18"><span class="cite-bracket">[</span>18<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-19" class="reference"><a href="#cite_note-19"><span class="cite-bracket">[</span>19<span class="cite-bracket">]</span></a></sup> over the C shell's alleged defects in syntax, missing features, and poor implementation.
</p>
<ul><li>Syntax defects: were generally simple but unnecessary inconsistencies in the definition of the language. For example, the <code>set</code>, <code>setenv</code> and <code>alias</code> commands all did basically the same thing, namely, associate a name with a string or set of words. But all three had slight but unnecessary differences. An equal sign was required for a <code>set</code> but not for <code>setenv</code> or <code>alias</code>; parentheses were required around a word list for a <code>set</code> but not for <code>setenv</code> or <code>alias</code>, etc. Similarly, the <code>if</code>, <code>switch</code> and looping constructs use needlessly different keywords (<code>endif</code>, <code>endsw</code> and <code>end</code>) to terminate the nested blocks.</li>
<li>Missing features: most commonly cited are the lack of ability to manipulate the <a href="Stdio" class="mw-redirect" title="Stdio">stdio</a> file handles independently and support for functions. Although lacking support for functions, aliases serve as workaround. For multiple lines of code, aliases must be within single quotes, and each end of line must precede a backslash (the end of the last line must precede a single quote to delimit the end of the alias). Recursion is favorable over aliases in scripts as workaround for functions (an example is given below).</li>
<li>The implementation: which used an ad hoc <a href="Parsing" title="Parsing">parser</a>, has drawn the most serious criticism. By the early 1970s, <a href="Compiler" title="Compiler">compiler</a> technology was sufficiently mature<sup id="cite_ref-20" class="reference"><a href="#cite_note-20"><span class="cite-bracket">[</span>20<span class="cite-bracket">]</span></a></sup> that most new language implementations used either a <a href="Top-down_parsing" title="Top-down parsing">top-down</a> or <a href="Bottom-up_parsing" title="Bottom-up parsing">bottom-up parser</a> capable of recognizing a fully recursive <a href="Formal_grammar" title="Formal grammar">grammar</a>. It is not known why an ad hoc design was chosen instead for the C shell. It may be simply that, as Joy put it in an interview in 2009, "When I started doing this stuff with Unix, I wasn’t a very good programmer."<sup id="cite_ref-21" class="reference"><a href="#cite_note-21"><span class="cite-bracket">[</span>21<span class="cite-bracket">]</span></a></sup> The ad hoc design meant that the C shell language was not fully recursive. There was a limit to how complex a command it could handle.</li></ul>
<p>It worked for most interactively typed commands, but for the more complex commands a user might write in a script, it could easily fail, producing only a cryptic error message or an unwelcome result. For example, the C shell could not support piping between control structures. Attempting to pipe the output of a <code>foreach</code> command into <code><a href="Grep" title="Grep">grep</a></code> simply didn't work. (The work-around, which works for many of the complaints related to the parser, is to break the code up into separate scripts. If the <code>foreach</code> is moved to a separate script, piping works because scripts are run by forking a new copy of csh that does inherit the correct stdio handles. It's also possible to break codes in a single file. An example is given below on how to break codes in a single file.)
</p><p>Another example is the unwelcome behavior in the following fragments. Both of these appear to mean, "If 'myfile' does not exist, create it by writing 'mytext' into it." But the version on the right always creates an empty file because the C shell's order of evaluation is to look for and evaluate I/O redirection operators on each command line as it reads it, before examining the rest of the line to see whether it contains a control structure.
</p>
<div class="columns-start columns-4" style="width: 90em"><div class="column">
<div class="mw-highlight mw-highlight-lang-bash mw-content-ltr" dir="ltr"><pre><span class="c1"># Works as expected</span>
<span class="k">if</span><span class="w"> </span><span class="o">(</span><span class="w"> </span>!<span class="w"> </span>-e<span class="w"> </span>myfile<span class="w"> </span><span class="o">)</span><span class="w"> </span><span class="k">then</span>
<span class="w"> </span><span class="nb">echo</span><span class="w"> </span>mytext<span class="w"> </span>><span class="w"> </span>myfile
endif
</pre></div>
</div><div class="column">
<div class="mw-highlight mw-highlight-lang-csh mw-content-ltr" dir="ltr"><pre><span class="c"># Always creates an empty file</span>
<span class="k">if</span> <span class="o">(</span>! -e myfile<span class="o">)</span> <span class="nb">echo </span>mytext > myfile
</pre></div>
</div><div class="column">
<div class="mw-highlight mw-highlight-lang-csh mw-content-ltr" dir="ltr"><pre><span class="c"># Workaround (only for tcsh)</span>
<span class="k">if</span> <span class="o">(</span>! -e myfile<span class="o">)</span> <span class="nb">eval</span> <span class="s2">"echo mytext > myfile"</span>
</pre></div>
<div class="mw-highlight mw-highlight-lang-csh mw-content-ltr" dir="ltr"><pre><span class="c"># Second workaround (for csh and tcsh)</span>
<span class="o">(</span> <span class="nb">exit</span> <span class="o">(</span> -e myfile <span class="o">)</span> && <span class="o">(</span> <span class="o">(</span> <span class="nb">echo </span>mytext > myfile <span class="o">)</span> >& /dev/null || <span class="nb">echo </span>Cannot create file. <span class="o">)</span> || <span class="nb">echo </span>File exists.
</pre></div></div><div style="clear: both"></div></div>
<p>The implementation is also criticized for its notoriously poor error messages, e.g., "0: Event not found.", which yields no useful information about the problem.
</p><p>However, by practicing, it's possible to overcome those deficiencies (thus instructing the programmer to take better and safer approaches on implementing a script).
</p><p>The "0: Event not found." error implies there aren't saved commands in the history. The history may not work properly in scripts, but having a pre-set of commands in a variable serves as workaround.
</p>
<div class="mw-highlight mw-highlight-lang-csh mw-content-ltr" dir="ltr"><pre><span class="c">#!/bin/csh -f</span>
<span class="nb">set </span><span class="nv">cmdlist</span> <span class="o">=</span> <span class="o">(</span> <span class="s1">'date # 1'</span><span class="se">\</span>
<span class="s1">'uname # 2'</span><span class="se">\</span>
<span class="s1">'tty # 3'</span><span class="se">\</span>
<span class="s1">'id # 4'</span> <span class="o">)</span>
<span class="nb">echo</span> -n <span class="s1">'Enter a number to execute a command from the history: '</span>
<span class="nb">set </span><span class="nv">cmdexec</span> <span class="o">=</span> <span class="s2">"$<"</span>
<span class="o">(</span> <span class="nb">exit</span> <span class="o">(</span> ! <span class="o">(</span> <span class="s2">"$cmdexec"</span> > 0 && <span class="se">\</span>
<span class="s2">"$cmdexec"</span> <<span class="o">=</span> <span class="s2">"$#cmdlist"</span> <span class="o">)</span> <span class="o">)</span> <span class="o">)</span> >& /dev/null
<span class="k">if</span> <span class="o">(</span> <span class="s2">"$status"</span> <span class="o">)</span> <span class="k">then</span>
<span class="k"> </span><span class="nb">echo</span> <span class="s1">'Invalid event number.'</span>
<span class="k">foreach </span>cmd <span class="o">(</span> <span class="nv">$cmdlist</span>:q <span class="o">)</span>
<span class="nb">echo</span> <span class="s2">"$cmd"</span>
<span class="k">end</span>
<span class="k"> </span><span class="nb">exit</span> -1
<span class="k">endif</span>
<span class="nb">eval</span> <span class="s2">"$cmdlist[$cmdexec]"</span>
</pre></div>
<p>Prefer breaking codes by recursing the script as workaround for functions.
</p>
<div class="mw-highlight mw-highlight-lang-csh mw-content-ltr" dir="ltr"><pre><span class="c">#!/bin/csh -f</span>
<span class="k">if</span> <span class="o">(</span> ! <span class="s2">"$?main"</span> <span class="o">)</span> <span class="k">then</span>
<span class="k"> if</span> <span class="o">(</span> ! <span class="s2">"$?0"</span> <span class="o">)</span> <span class="k">then</span>
<span class="k"> </span><span class="nb">echo</span> <span class="s1">'You must run this script by explicitly calling its file.'</span>
<span class="nb">exit</span> -1
<span class="k">endif</span>
<span class="k"> </span><span class="nb">alias </span>function <span class="s1">'set argv = ( \!* ) ; source "$main"'</span>
<span class="nb">set </span><span class="nv">main</span> <span class="o">=</span> <span class="s2">"$0"</span>
<span class="nb">set </span><span class="nv">ret</span> <span class="o">=</span> <span class="s2">"`function myfunc`"</span>
<span class="nb">echo</span> <span class="s2">"$ret"</span>
<span class="nb">exit</span>
<span class="k">endif</span>
<span class="k">goto</span> <span class="s2">"$1"</span> <span class="p">;</span> <span class="nb">shift</span>
myfunc:
function myfunc2
<span class="nb">echo</span> <span class="s2">"A function."</span>
<span class="nb">exit</span>
myfunc2:
<span class="nb">echo</span> <span class="s2">"Another function."</span>
<span class="nb">exit</span>
</pre></div>
<div class="mw-heading mw-heading2"><h2 id="Influence">Influence</h2></div>
<p>The C shell was extremely successful in introducing a large number of innovations including the <a class="mw-selflink-fragment" href="#History">history</a> mechanism, <a class="mw-selflink-fragment" href="#Aliases">aliases</a>, <a class="mw-selflink-fragment" href="#Tilde_notation">tilde notation</a>, interactive filename completion, an expression grammar built into the shell, and more, that have since been copied by other Unix shells. But in contrast to <a href="Bourne_shell" title="Bourne shell">sh</a>, which has spawned a large number of independently developed clones, including <a href="KornShell" title="KornShell">ksh</a> and <a href="Bash_(Unix_shell)" title="Bash (Unix shell)">bash</a>, only two csh <a href="Clone_(computing)" title="Clone (computing)">clones</a> are known. (Since <a href="Tcsh" title="Tcsh">tcsh</a> was based on the csh code originally written by Bill Joy, it is not considered a clone.)
</p><p>In 1986, <a href="Allen_Holub" title="Allen Holub">Allen Holub</a> wrote <i>On Command: Writing a Unix-Like Shell for <a href="MS-DOS" title="MS-DOS">MS-DOS</a></i>,<sup id="cite_ref-22" class="reference"><a href="#cite_note-22"><span class="cite-bracket">[</span>22<span class="cite-bracket">]</span></a></sup> a book describing a program he had written called "SH" but which in fact copied the language design and features of csh, not sh. Companion diskettes containing full source for SH and for a basic set of Unix-like utilities (cat, cp, grep, etc.) were available for $25 and $30, respectively, from the publisher. The control structures, expression grammar, history mechanism and other features in Holub's SH were identical to those of the C shell.
</p><p>In 1988, Hamilton Laboratories began shipping <a href="Hamilton_C_shell" title="Hamilton C shell">Hamilton C shell</a> for <a href="OS/2" title="OS/2">OS/2</a>.<sup id="cite_ref-23" class="reference"><a href="#cite_note-23"><span class="cite-bracket">[</span>23<span class="cite-bracket">]</span></a></sup> It included both a csh clone and a set of Unix-like utilities. In 1992, Hamilton C shell was released for <a href="Windows_NT" title="Windows NT">Windows NT</a>.<sup id="cite_ref-HamiltonReleaseNotes_24-0" class="reference"><a href="#cite_note-HamiltonReleaseNotes-24"><span class="cite-bracket">[</span>24<span class="cite-bracket">]</span></a></sup> The Windows version continues to be actively supported but the OS/2 version was discontinued in 2003.<sup id="cite_ref-HamiltonReleaseNotes_24-1" class="reference"><a href="#cite_note-HamiltonReleaseNotes-24"><span class="cite-bracket">[</span>24<span class="cite-bracket">]</span></a></sup> An early 1990 quick reference<sup id="cite_ref-25" class="reference"><a href="#cite_note-25"><span class="cite-bracket">[</span>25<span class="cite-bracket">]</span></a></sup> described the intent as "full compliance with the entire C shell language (except <a class="mw-selflink-fragment" href="#Job_control">job control</a>)" but with improvements to the language design and adaptation to the differences between Unix and a PC. The most important improvement was a <a href="Top-down_parsing" title="Top-down parsing">top-down parser</a> that allowed <a href="Control_structure" class="mw-redirect" title="Control structure">control structures</a> to be nested or piped, something the original C shell could not support, given its ad hoc parser. Hamilton also added new language features including built-in and user-defined procedures, block-structured local variables and floating point arithmetic. Adaptation to a PC included support for the filename and other conventions on a PC and the use of <a href="Thread_(computer_science)" class="mw-redirect" title="Thread (computer science)">threads</a> instead of <a href="Fork_(system_call)" title="Fork (system call)">forks</a> (which were not available under either OS/2 or Windows) to achieve <a href="Parallel_computing" title="Parallel computing">parallelism</a>, e.g., in setting up a pipeline.
</p>
<div class="mw-heading mw-heading2"><h2 id="See_also">See also</h2></div>
<ul><li><a href="Command-line_interpreter" class="mw-redirect" title="Command-line interpreter">Command-line interpreter</a></li>
<li><a href="Comparison_of_command_shells" title="Comparison of command shells">Comparison of command shells</a></li></ul>
<div class="mw-heading mw-heading2"><h2 id="References">References</h2></div>
<style data-mw-deduplicate="TemplateStyles:r1239543626">
/* start https://en.wikipedia.org/ */
.mw-parser-output .reflist{margin-bottom:0.5em;list-style-type:decimal}@media screen{.mw-parser-output .reflist{font-size:90%}}.mw-parser-output .reflist .references{font-size:100%;margin-bottom:0;list-style-type:inherit}.mw-parser-output .reflist-columns-2{column-width:30em}.mw-parser-output .reflist-columns-3{column-width:25em}.mw-parser-output .reflist-columns{margin-top:0.3em}.mw-parser-output .reflist-columns ol{margin-top:0}.mw-parser-output .reflist-columns li{page-break-inside:avoid;break-inside:avoid-column}.mw-parser-output .reflist-upper-alpha{list-style-type:upper-alpha}.mw-parser-output .reflist-upper-roman{list-style-type:upper-roman}.mw-parser-output .reflist-lower-alpha{list-style-type:lower-alpha}.mw-parser-output .reflist-lower-greek{list-style-type:lower-greek}.mw-parser-output .reflist-lower-roman{list-style-type:lower-roman}
/* end https://en.wikipedia.org/ */
</style><div class="reflist">
<div class="mw-references-wrap mw-references-columns"><ol class="references">
<li id="cite_note-1"><span class="mw-cite-backlink"><b><a href="#cite_ref-1">^</a></b></span> <span class="reference-text"><style data-mw-deduplicate="TemplateStyles:r1238218222">
/* start https://en.wikipedia.org/ */
.mw-parser-output cite.citation{font-style:inherit;word-wrap:break-word}.mw-parser-output .citation q{quotes:"\"""\"""'""'"}.mw-parser-output .citation:target{background-color:rgba(0,127,255,0.133)}.mw-parser-output .id-lock-free.id-lock-free a{background:url("./mw/Lock-green.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-limited.id-lock-limited a,.mw-parser-output .id-lock-registration.id-lock-registration a{background:url("./mw/Lock-gray-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-subscription.id-lock-subscription a{background:url("./mw/Lock-red-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .cs1-ws-icon a{background:url("./mw/Wikisource-logo.svg")right 0.1em center/12px no-repeat}body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-free a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-limited a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-registration a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-subscription a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .cs1-ws-icon a{background-size:contain;padding:0 1em 0 0}.mw-parser-output .cs1-code{color:inherit;background:inherit;border:none;padding:inherit}.mw-parser-output .cs1-hidden-error{display:none;color:var(--color-error,#d33)}.mw-parser-output .cs1-visible-error{color:var(--color-error,#d33)}.mw-parser-output .cs1-maint{display:none;color:#085;margin-left:0.3em}.mw-parser-output .cs1-kern-left{padding-left:0.2em}.mw-parser-output .cs1-kern-right{padding-right:0.2em}.mw-parser-output .citation .mw-selflink{font-weight:inherit}@media screen{.mw-parser-output .cs1-format{font-size:95%}html.skin-theme-clientpref-night .mw-parser-output .cs1-maint{color:#18911f}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .cs1-maint{color:#18911f}}
/* end https://en.wikipedia.org/ */
</style><cite id="CITEREFZoulas2016" class="citation cs1">Zoulas, Christos (24 November 2016). <a rel="nofollow" class="external text" href="https://web.archive.org/web/20161125044614/http://mx.gw.com/pipermail/tcsh/2016-November/005021.html">"tcsh-6.20.00 is now available!"</a>. <i>mx.gw.com</i>. Archived from <a rel="nofollow" class="external text" href="http://mx.gw.com/pipermail/tcsh/2016-November/005021.html">the original</a> on 25 November 2016<span class="reference-accessdate">. Retrieved <span class="nowrap">24 November</span> 2016</span>.</cite></span>
</li>
<li id="cite_note-2"><span class="mw-cite-backlink"><b><a href="#cite_ref-2">^</a></b></span> <span class="reference-text">Harley Hahn, <a rel="nofollow" class="external text" href="http://unix.harley.com/instructors/timeline.html">Harley Hahn's Guide to Unix and Linux</a> <a rel="nofollow" class="external text" href="https://web.archive.org/web/20190824231900/http://unix.harley.com/instructors/timeline.html">Archived</a> 24 August 2019 at the <a href="Wayback_Machine" title="Wayback Machine">Wayback Machine</a>.</span>
</li>
<li id="cite_note-3"><span class="mw-cite-backlink"><b><a href="#cite_ref-3">^</a></b></span> <span class="reference-text"><a rel="nofollow" class="external text" href="http://coe.berkeley.edu/labnotes/history_unix.html">Berkeley Engineering Lab Notes, Volume 1, Issue 2, October 2001</a> <a rel="nofollow" class="external text" href="https://web.archive.org/web/20100709223314/http://coe.berkeley.edu/labnotes/history_unix.html">Archived</a> 9 July 2010 at the <a href="Wayback_Machine" title="Wayback Machine">Wayback Machine</a>.</span>
</li>
<li id="cite_note-4"><span class="mw-cite-backlink"><b><a href="#cite_ref-4">^</a></b></span> <span class="reference-text"><a rel="nofollow" class="external text" href="http://www.kitebird.com/csh-tcsh-book/csh-intro.pdf"><i>An Introduction to the C shell</i></a> <a rel="nofollow" class="external text" href="https://web.archive.org/web/20180713012111/http://www.kitebird.com/csh-tcsh-book/csh-intro.pdf">Archived</a> 13 July 2018 at the <a href="Wayback_Machine" title="Wayback Machine">Wayback Machine</a> by <a href="Bill_Joy" title="Bill Joy">Bill Joy</a>.</span>
</li>
<li id="cite_note-5"><span class="mw-cite-backlink"><b><a href="#cite_ref-5">^</a></b></span> <span class="reference-text"><a rel="nofollow" class="external text" href="https://launchpad.net/ubuntu/+source/csh">Ubuntu - Details of package csh</a>. launchpad.net.</span>
</li>
<li id="cite_note-6"><span class="mw-cite-backlink"><b><a href="#cite_ref-6">^</a></b></span> <span class="reference-text"><a rel="nofollow" class="external text" href="https://tracker.debian.org/pkg/csh">Debian - Details of package csh</a>. tracker.debian.org.</span>
</li>
<li id="cite_note-7"><span class="mw-cite-backlink"><b><a href="#cite_ref-7">^</a></b></span> <span class="reference-text"><a rel="nofollow" class="external text" href="https://launchpad.net/ubuntu/+source/tcsh">Ubuntu - Details of package tcsh</a>. launchpad.net.</span>
</li>
<li id="cite_note-8"><span class="mw-cite-backlink"><b><a href="#cite_ref-8">^</a></b></span> <span class="reference-text"><a rel="nofollow" class="external text" href="https://tracker.debian.org/pkg/tcsh">Debian - Details of package tcsh</a>. tracker.debian.org.</span>
</li>
<li id="cite_note-Greer-9"><span class="mw-cite-backlink"><b><a href="#cite_ref-Greer_9-0">^</a></b></span> <span class="reference-text">
<cite id="CITEREFKen_Greer1983" class="citation newsgroup cs1">Ken Greer (3 October 1983). <a rel="nofollow" class="external text" href="https://groups.google.com/group/net.sources/msg/7073bf41cc5da330?hl=en">"C shell with command and filename recognition/completion"</a>. <a href="Usenet_newsgroup" title="Usenet newsgroup">Newsgroup</a>: <a rel="nofollow" class="external text" href="news:net.sources">net.sources</a><span class="reference-accessdate">. Retrieved <span class="nowrap">29 December</span> 2010</span>.</cite></span>
</li>
<li id="cite_note-10"><span class="mw-cite-backlink"><b><a href="#cite_ref-10">^</a></b></span> <span class="reference-text"><a rel="nofollow" class="external text" href="https://web.archive.org/web/20060117151444/http://www.tcsh.org/tcsh.html/DESCRIPTION.html">tcsh(1) man page</a>. tcsh.</span>
</li>
<li id="cite_note-11"><span class="mw-cite-backlink"><b><a href="#cite_ref-11">^</a></b></span> <span class="reference-text">Fixes file in tcsh-17 June 2000.</span>
</li>
<li id="cite_note-12"><span class="mw-cite-backlink"><b><a href="#cite_ref-12">^</a></b></span> <span class="reference-text"><a rel="nofollow" class="external text" href="https://groups.google.com/group/comp.lang.misc/msg/d58db4799c33e093?hl=en&dmode=source"><i>Re: Late Bloomers Revisited</i></a> USENET post to comp.lang.misc by Piercarlo "Peter" Grandi, Dept of CS, UCW Aberystwyth, UK, 17 December 1989.</span>
</li>
<li id="cite_note-13"><span class="mw-cite-backlink"><b><a href="#cite_ref-13">^</a></b></span> <span class="reference-text">Pronounced <i>"bang, bang"</i></span>
</li>
<li id="cite_note-USDT-14"><span class="mw-cite-backlink"><b><a href="#cite_ref-USDT_14-0">^</a></b></span> <span class="reference-text"><cite id="CITEREFTroy1990" class="citation book cs1">Troy, Douglas (1990). <i>UNIX Systems</i>. Computing Fundamentals. Benjamin/Cumming Publishing Company. p. 25.</cite></span>
</li>
<li id="cite_note-bourne198310-15"><span class="mw-cite-backlink"><b><a href="#cite_ref-bourne198310_15-0">^</a></b></span> <span class="reference-text"><cite id="CITEREFBourne,_Stephen_R.1983" class="citation news cs1">Bourne, Stephen R. (October 1983). <a rel="nofollow" class="external text" href="https://archive.org/stream/byte-magazine-1983-10/1983_10_BYTE_08-10_UNIX#page/n187/mode/2up">"The Unix Shell"</a>. <i>BYTE</i>. p. 187<span class="reference-accessdate">. Retrieved <span class="nowrap">30 January</span> 2015</span>.</cite></span>
</li>
<li id="cite_note-16"><span class="mw-cite-backlink"><b><a href="#cite_ref-16">^</a></b></span> <span class="reference-text"><cite class="citation book cs1"><a rel="nofollow" class="external text" href="https://www.1000bit.it/ad/bro/charles/CharlesRiverSystem-Universe.pdf"><i>The Insider's Guide To The Universe</i></a> <span class="cs1-format">(PDF)</span>. Charles River Data Systems, Inc. 1983. p. 13.</cite></span>
</li>
<li id="cite_note-17"><span class="mw-cite-backlink"><b><a href="#cite_ref-17">^</a></b></span> <span class="reference-text"><i>IEEE Standard for Information Technology, Portable Operating System Interface (POSIX), Part 2: Shell and Utilities, Volume 2</i>. IEEE Std 1003.2-1992, pp. 766-767. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>1-55937-255-9</bdi>.</span>
</li>
<li id="cite_note-18"><span class="mw-cite-backlink"><b><a href="#cite_ref-18">^</a></b></span> <span class="reference-text"><a rel="nofollow" class="external text" href="http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/"><i>Csh Programming Considered Harmful</i></a> by Tom Christiansen</span>
</li>
<li id="cite_note-19"><span class="mw-cite-backlink"><b><a href="#cite_ref-19">^</a></b></span> <span class="reference-text"><a rel="nofollow" class="external text" href="http://www.grymoire.com/Unix/CshTop10.txt"><i>Top Ten Reasons not to use the C shell</i></a> by Bruce Barnett</span>
</li>
<li id="cite_note-20"><span class="mw-cite-backlink"><b><a href="#cite_ref-20">^</a></b></span> <span class="reference-text">David Gries (1971). <i>Compiler Construction for Digital Computers.</i> John Wiley & Sons. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>0-471-32776-X</bdi>.</span>
</li>
<li id="cite_note-21"><span class="mw-cite-backlink"><b><a href="#cite_ref-21">^</a></b></span> <span class="reference-text"><a rel="nofollow" class="external text" href="https://web.archive.org/web/20100330044908/http://fora.tv/2009/02/11/Bill_Joy_in_Conversation_with_Brent_Schlender">Bill Joy in Conversation with Brent Schlender, Churchill Club, Santa Clara, CA, 11 Feb 2009</a>.</span>
</li>
<li id="cite_note-22"><span class="mw-cite-backlink"><b><a href="#cite_ref-22">^</a></b></span> <span class="reference-text">
<cite id="CITEREFHolub1986–1987" class="citation book cs1"><a href="Allen_Holub" title="Allen Holub">Holub, Allen</a> (1986–1987). <i>On Command: Writing a Unix-Like Shell for MS-DOS</i> (Second ed.). M&T Books, Redwood City, CA. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>0-934375-29-1</bdi>.</cite></span>
</li>
<li id="cite_note-23"><span class="mw-cite-backlink"><b><a href="#cite_ref-23">^</a></b></span> <span class="reference-text"><cite id="CITEREFHamilton" class="citation journal cs1">Hamilton, Douglas. <a rel="nofollow" class="external text" href="http://hamiltonlabs.com/Archives/Hamilton-C-Shell-Announcement-Douglas-A-Hamilton-IBM-Personal-Systems-Developer-Summer-1989.pdf">"Hamilton C shell Announcement"</a> <span class="cs1-format">(PDF)</span>. <i>IBM Personal Systems Developer</i> (Summer 1989): <span class="nowrap">119–</span>121<span class="reference-accessdate">. Retrieved <span class="nowrap">11 July</span> 2020</span>.</cite></span>
</li>
<li id="cite_note-HamiltonReleaseNotes-24"><span class="mw-cite-backlink">^ <a href="#cite_ref-HamiltonReleaseNotes_24-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-HamiltonReleaseNotes_24-1"><sup><i><b>b</b></i></sup></a></span> <span class="reference-text">
<cite id="CITEREFHamilton2017" class="citation web cs1">Hamilton, Nicole (5 March 2017). <a rel="nofollow" class="external text" href="http://hamiltonlabs.com/ReleaseNotes.htm">"Hamilton C shell for Windows Release Notes 5.2.g"</a>. Hamilton Laboratories, Redmond, WA<span class="reference-accessdate">. Retrieved <span class="nowrap">3 April</span> 2018</span>.</cite></span>
</li>
<li id="cite_note-25"><span class="mw-cite-backlink"><b><a href="#cite_ref-25">^</a></b></span> <span class="reference-text"><cite class="citation book cs1"><a rel="nofollow" class="external text" href="http://hamiltonlabs.com/Archives/1990-07-10-Hamilton-C-shell-Quick-Reference.pdf"><i>Hamilton C shell Quick Reference</i></a> <span class="cs1-format">(PDF)</span>. Hamilton Laboratories, Wayland, MA. 1988–1990<span class="reference-accessdate">. Retrieved <span class="nowrap">11 July</span> 2020</span>.</cite></span>
</li>
</ol></div></div>
<div class="mw-heading mw-heading2"><h2 id="Further_reading">Further reading</h2></div>
<ul><li><cite id="CITEREFAndersonPaul_Anderson1986" class="citation book cs1">Anderson, Gail; Paul Anderson (1986). <a rel="nofollow" class="external text" href="https://archive.org/details/unixcshellfieldg00ande"><i>The UNIX C Shell Field Guide</i></a>. Prentice-Hall. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>0-13-937468-X</bdi>.</cite></li>
<li><cite id="CITEREFWang1988" class="citation book cs1">Wang, Paul (1988). <span class="id-lock-registration" title="Free registration required"><a rel="nofollow" class="external text" href="https://archive.org/details/introductiontobe0000wang"><i>An Introduction to Berkeley UNIX</i></a></span>. Wadsworth Pub. Co. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>0-534-08862-7</bdi>.</cite></li>
<li><cite id="CITEREFDuBois1995" class="citation book cs1">DuBois, Paul (1995). <a rel="nofollow" class="external text" href="https://archive.org/details/usingcshtcsh00dubo"><i>Using csh & tcsh</i></a>. O'Reilly & Associates. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>1-56592-132-1</bdi>.</cite></li>
<li><cite id="CITEREFArick1993" class="citation book cs1">Arick, Martin R. (1993). <i>UNIX C Shell Desk Reference</i>. John Wiley & Sons. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>0-471-55680-7</bdi>.</cite></li>
<li><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://web.archive.org/web/20110819120933/http://klaatu.canisius.edu/ONLINESTUFF/UNIX/shellprogramming.html">"Introduction to C Shell Programming"</a>. Canisius College Computer Science Department. Archived from <a rel="nofollow" class="external text" href="http://klaatu.canisius.edu/ONLINESTUFF/UNIX/shellprogramming.html">the original</a> on 19 August 2011<span class="reference-accessdate">. Retrieved <span class="nowrap">23 June</span> 2010</span>.</cite></li></ul>
<div class="mw-heading mw-heading2"><h2 id="External_links">External links</h2></div>
<style data-mw-deduplicate="TemplateStyles:r1290876196">
/* start https://en.wikipedia.org/ */
.mw-parser-output .side-box{margin:4px 0;box-sizing:border-box;border:1px solid #aaa;font-size:88%;line-height:1.25em;background-color:var(--background-color-interactive-subtle,#f8f9fa);display:flow-root}.mw-parser-output .infobox .side-box{font-size:100%}.mw-parser-output .side-box-abovebelow,.mw-parser-output .side-box-text{padding:0.25em 0.9em}.mw-parser-output .side-box-image{padding:2px 0 2px 0.9em;text-align:center}.mw-parser-output .side-box-imageright{padding:2px 0.9em 2px 0;text-align:center}@media(min-width:500px){.mw-parser-output .side-box-flex{display:flex;align-items:center}.mw-parser-output .side-box-text{flex:1;min-width:0}}@media(min-width:720px){.mw-parser-output .side-box{width:238px}.mw-parser-output .side-box-right{clear:right;float:right;margin-left:1em}.mw-parser-output .side-box-left{margin-right:1em}}
/* end https://en.wikipedia.org/ */
</style><style data-mw-deduplicate="TemplateStyles:r1237033735">
/* start https://en.wikipedia.org/ */
@media print{body.ns-0 .mw-parser-output .sistersitebox{display:none!important}}@media screen{html.skin-theme-clientpref-night .mw-parser-output .sistersitebox img[src*="Wiktionary-logo-en-v2.svg"]{background-color:white}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .sistersitebox img[src*="Wiktionary-logo-en-v2.svg"]{background-color:white}}
/* end https://en.wikipedia.org/ */
</style><div class="side-box side-box-right sistersitebox">
<div class="side-box-flex">
<div class="side-box-image"><span class="noviewer" typeof="mw:File"></span></div>
<div class="side-box-text plainlist">Wikibooks has a book on the topic of: <i><b><a href="https://en.wikibooks.org/wiki/C_Shell_Scripting" class="extiw external" title="wikibooks:C Shell Scripting">C Shell Scripting</a></b></i></div></div>
</div>
<ul><li><a rel="nofollow" class="external text" href="https://docs.freebsd.org/44doc/usd/04.csh/paper.html"><i>An Introduction to the C shell</i></a> by <a href="Bill_Joy" title="Bill Joy">William Joy</a>.</li>
<li><a rel="nofollow" class="external text" href="https://docstore.mik.ua/orelly/linux/lnut/ch08_01.htm">Linux in a Nutshell: Chapter 8. csh and tcsh</a>.</li>
<li><a rel="nofollow" class="external text" href="https://web.archive.org/web/20100212221424/http://www.tcsh.org/Home">tcsh home page</a>.</li>
<li><a rel="nofollow" class="external text" href="https://web.archive.org/web/20160419222736/http://www.tcsh.org/tcsh.html/top.html">tcsh(1) man page</a>.</li>
<li><a rel="nofollow" class="external text" href="https://github.com/tcsh-org/tcsh">most recent available tcsh source code</a>.</li>
<li><a rel="nofollow" class="external text" href="https://minnie.tuhs.org/cgi-bin/utree.pl?file=2BSD/src/csh">historical 2BSD csh source code</a> dated 2 February 1980.</li>
<li><a rel="nofollow" class="external text" href="https://minnie.tuhs.org/cgi-bin/utree.pl">The Unix Tree</a>, complete historical Unix distributions.</li>
<li><a rel="nofollow" class="external text" href="http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/">Csh programming considered harmful</a>.</li>
<li><a rel="nofollow" class="external text" href="https://www.grymoire.com/Unix/CshTop10.txt">Top Ten Reasons not to use the C shell</a>.</li></ul>
<div class="navbox-styles"><style data-mw-deduplicate="TemplateStyles:r1129693374">
/* start https://en.wikipedia.org/ */
.mw-parser-output .hlist dl,.mw-parser-output .hlist ol,.mw-parser-output .hlist ul{margin:0;padding:0}.mw-parser-output .hlist dd,.mw-parser-output .hlist dt,.mw-parser-output .hlist li{margin:0;display:inline}.mw-parser-output .hlist.inline,.mw-parser-output .hlist.inline dl,.mw-parser-output .hlist.inline ol,.mw-parser-output .hlist.inline ul,.mw-parser-output .hlist dl dl,.mw-parser-output .hlist dl ol,.mw-parser-output .hlist dl ul,.mw-parser-output .hlist ol dl,.mw-parser-output .hlist ol ol,.mw-parser-output .hlist ol ul,.mw-parser-output .hlist ul dl,.mw-parser-output .hlist ul ol,.mw-parser-output .hlist ul ul{display:inline}.mw-parser-output .hlist .mw-empty-li{display:none}.mw-parser-output .hlist dt::after{content:": "}.mw-parser-output .hlist dd::after,.mw-parser-output .hlist li::after{content:" · ";font-weight:bold}.mw-parser-output .hlist dd:last-child::after,.mw-parser-output .hlist dt:last-child::after,.mw-parser-output .hlist li:last-child::after{content:none}.mw-parser-output .hlist dd dd:first-child::before,.mw-parser-output .hlist dd dt:first-child::before,.mw-parser-output .hlist dd li:first-child::before,.mw-parser-output .hlist dt dd:first-child::before,.mw-parser-output .hlist dt dt:first-child::before,.mw-parser-output .hlist dt li:first-child::before,.mw-parser-output .hlist li dd:first-child::before,.mw-parser-output .hlist li dt:first-child::before,.mw-parser-output .hlist li li:first-child::before{content:" (";font-weight:normal}.mw-parser-output .hlist dd dd:last-child::after,.mw-parser-output .hlist dd dt:last-child::after,.mw-parser-output .hlist dd li:last-child::after,.mw-parser-output .hlist dt dd:last-child::after,.mw-parser-output .hlist dt dt:last-child::after,.mw-parser-output .hlist dt li:last-child::after,.mw-parser-output .hlist li dd:last-child::after,.mw-parser-output .hlist li dt:last-child::after,.mw-parser-output .hlist li li:last-child::after{content:")";font-weight:normal}.mw-parser-output .hlist ol{counter-reset:listitem}.mw-parser-output .hlist ol>li{counter-increment:listitem}.mw-parser-output .hlist ol>li::before{content:" "counter(listitem)"\a0 "}.mw-parser-output .hlist dd ol>li:first-child::before,.mw-parser-output .hlist dt ol>li:first-child::before,.mw-parser-output .hlist li ol>li:first-child::before{content:" ("counter(listitem)"\a0 "}
/* end https://en.wikipedia.org/ */
</style><style data-mw-deduplicate="TemplateStyles:r1236075235">
/* start https://en.wikipedia.org/ */
.mw-parser-output .navbox{box-sizing:border-box;border:1px solid #a2a9b1;width:100%;clear:both;font-size:88%;text-align:center;padding:1px;margin:1em auto 0}.mw-parser-output .navbox .navbox{margin-top:0}.mw-parser-output .navbox+.navbox,.mw-parser-output .navbox+.navbox-styles+.navbox{margin-top:-1px}.mw-parser-output .navbox-inner,.mw-parser-output .navbox-subgroup{width:100%}.mw-parser-output .navbox-group,.mw-parser-output .navbox-title,.mw-parser-output .navbox-abovebelow{padding:0.25em 1em;line-height:1.5em;text-align:center}.mw-parser-output .navbox-group{white-space:nowrap;text-align:right}.mw-parser-output .navbox,.mw-parser-output .navbox-subgroup{background-color:#fdfdfd}.mw-parser-output .navbox-list{line-height:1.5em;border-color:#fdfdfd}.mw-parser-output .navbox-list-with-group{text-align:left;border-left-width:2px;border-left-style:solid}.mw-parser-output tr+tr>.navbox-abovebelow,.mw-parser-output tr+tr>.navbox-group,.mw-parser-output tr+tr>.navbox-image,.mw-parser-output tr+tr>.navbox-list{border-top:2px solid #fdfdfd}.mw-parser-output .navbox-title{background-color:#ccf}.mw-parser-output .navbox-abovebelow,.mw-parser-output .navbox-group,.mw-parser-output .navbox-subgroup .navbox-title{background-color:#ddf}.mw-parser-output .navbox-subgroup .navbox-group,.mw-parser-output .navbox-subgroup .navbox-abovebelow{background-color:#e6e6ff}.mw-parser-output .navbox-even{background-color:#f7f7f7}.mw-parser-output .navbox-odd{background-color:transparent}.mw-parser-output .navbox .hlist td dl,.mw-parser-output .navbox .hlist td ol,.mw-parser-output .navbox .hlist td ul,.mw-parser-output .navbox td.hlist dl,.mw-parser-output .navbox td.hlist ol,.mw-parser-output .navbox td.hlist ul{padding:0.125em 0}.mw-parser-output .navbox .navbar{display:block;font-size:100%}.mw-parser-output .navbox-title .navbar{float:left;text-align:left;margin-right:0.5em}body.skin--responsive .mw-parser-output .navbox-image img{max-width:none!important}@media print{body.ns-0 .mw-parser-output .navbox{display:none!important}}
/* end https://en.wikipedia.org/ */
</style></div><div role="navigation" class="navbox" aria-labelledby="Unix_shells49" style="padding:3px"><table class="nowraplinks hlist mw-collapsible autocollapse navbox-inner" style="border-spacing:0;background:transparent;color:inherit"><tbody><tr><th scope="col" class="navbox-title" colspan="2"><style data-mw-deduplicate="TemplateStyles:r1239400231">
/* start https://en.wikipedia.org/ */
.mw-parser-output .navbar{display:inline;font-size:88%;font-weight:normal}.mw-parser-output .navbar-collapse{float:left;text-align:left}.mw-parser-output .navbar-boxtext{word-spacing:0}.mw-parser-output .navbar ul{display:inline-block;white-space:nowrap;line-height:inherit}.mw-parser-output .navbar-brackets::before{margin-right:-0.125em;content:"[ "}.mw-parser-output .navbar-brackets::after{margin-left:-0.125em;content:" ]"}.mw-parser-output .navbar li{word-spacing:-0.125em}.mw-parser-output .navbar a>span,.mw-parser-output .navbar a>abbr{text-decoration:inherit}.mw-parser-output .navbar-mini abbr{font-variant:small-caps;border-bottom:none;text-decoration:none;cursor:inherit}.mw-parser-output .navbar-ct-full{font-size:114%;margin:0 7em}.mw-parser-output .navbar-ct-mini{font-size:114%;margin:0 4em}html.skin-theme-clientpref-night .mw-parser-output .navbar li a abbr{color:var(--color-base)!important}@media(prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .navbar li a abbr{color:var(--color-base)!important}}@media print{.mw-parser-output .navbar{display:none!important}}
/* end https://en.wikipedia.org/ */
</style><div id="Unix_shells49" style="font-size:114%;margin:0 4em"><a href="Unix_shell" title="Unix shell">Unix shells</a></div></th></tr><tr><td colspan="2" class="navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Almquist_shell" title="Almquist shell">Almquist</a></li>
<li><a href="Bash_(Unix_shell)" title="Bash (Unix shell)">Bash</a></li>
<li><a href="Bourne_shell" title="Bourne shell">Bourne</a></li>
<li><a href="Fish_(Unix_shell)" title="Fish (Unix shell)">fish</a></li>
<li><a href="Hamilton_C_shell" title="Hamilton C shell">Hamilton</a></li>
<li><a href="KornShell" title="KornShell">Korn</a></li>
<li><a href="PWB_shell" title="PWB shell">PWB</a></li>
<li><a href="Qshell" title="Qshell">Qshell</a></li>
<li><a href="Rc_(Unix_shell)" title="Rc (Unix shell)">rc</a></li>
<li><a href="Stand-alone_shell" title="Stand-alone shell">sash</a></li>
<li><a href="Tcsh" title="Tcsh">tcsh</a></li>
<li><a href="Thompson_shell" title="Thompson shell">Thompson</a></li>
<li><a href="Wish_(Unix_shell)" title="Wish (Unix shell)">Wish</a></li>
<li><a href="Z_shell" title="Z shell">Zsh</a></li></ul>
</div></td></tr><tr><td class="navbox-abovebelow" colspan="2"><div>
<ul><li><a href="Comparison_of_command_shells" title="Comparison of command shells">Comparison of command shells</a></li></ul>
</div></td></tr></tbody></table></div></div><!--htdig_noindex--><div><div class="zim-footer">
This article is issued from <a class="external text" title="Last edited on 2025-07-31" href="https://en.wikipedia.org/wiki/?title=C_shell&oldid=1303464240">Wikipedia</a>. The text is available under <a class="external text" href="https://creativecommons.org/licenses/by-sa/4.0/deed.en">Creative Commons Attribution-Share Alike 4.0</a> unless otherwise noted. Additional terms may apply for the media files.
</div>
</div><!--/htdig_noindex--></div>
</div>
</main>
</div>
</div>
</div>
</body></html>